<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改平台投放视频、文章广告')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-advertplatform-edit" th:object="${jiaqinAdvertPlatform}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">广告类型：</label>
<!--                <div class="col-sm-8">-->
<!--                    <select name="type" class="form-control m-b">-->
<!--                        <option value="">所有</option>-->
<!--                    </select>-->
<!--                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
<!--                </div>-->
                <div class="col-sm-8">
                    <select id="otype" name="type" class="form-control m-b" th:with="type=${@dict.getType('platform_type')}" onchange="showInput(this.value)">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">投放位置：</label>
                <div class="col-sm-8">
                    <select name="resId" class="form-control m-b">
                        <option th:each="dict : ${newsList}" th:text="${dict.title}" th:value="${dict.id}" th:field="*{resId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="jumpLinkDiv">
                <label class="col-sm-3 control-label is-required">广告：</label>
                <div class="col-sm-8">
                    <select id="jumpLink" name="jumpLink" class="form-control m-b">
                        <option th:each="dict : ${memberList}" th:text="${dict.username}" th:value="${dict.id}" th:field="*{jumpLink}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="titleDiv" style="display: none;">
                <label class="col-sm-3 control-label">广告标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group" id="imgUrlDiv" style="display: none;">
                <label class="col-sm-3 control-label">广告图片：</label>
<!--                <div class="col-sm-8">-->
<!--                    <input name="imgUrl" th:field="*{imgUrl}" class="form-control" type="text">-->
<!--                </div>-->
                <div class="col-sm-8">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="iCoverUpload">上传广告图片</button>
                        <div class="layui-upload-list" id="iCoverShow">
                            <img th:if="${jiaqinAdvertPlatform.imgUrl}" th:src="${jiaqinAdvertPlatform.imgUrl}" style="width: 112px; height: 63px; margin-right: 10px;">
                        </div>
                    </div>
                    <input id="imgUrl" name="imgUrl" th:field="*{imgUrl}" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group" id="pricelDiv" style="display: none;">
                <label class="col-sm-3 control-label">广告价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="text">
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">跳转链接：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="jumpLink" th:field="*{jumpLink}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group" id="contentDiv" style="display: none;">
                <label class="col-sm-3 control-label">广告内容：</label>
<!--                <div class="col-sm-8">-->
<!--                    <input name="content" th:field="*{content}" class="form-control" type="text">-->
<!--                </div>-->
                <div class="col-sm-8">
                    <div class="ibox-content no-padding">
                        <div class="summernote" th:utext="${jiaqinAdvertPlatform.content}">
                        </div>
                    </div>
                    <input  id="content"  name="content" th:field="*{content}" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
<!--                    <div class="radio-box">-->
<!--                        <input type="radio" name="status" value="">-->
<!--                        <label th:for="status" th:text="未知"></label>-->
<!--                    </div>-->
<!--                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
                    <div class="radio-box" th:each="dict : ${@dict.getType('platform_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">创建时间：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="input-group date">-->
<!--                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                        <input name="createdTime" th:value="${#dates.format(jiaqinAdvertPlatform.createdTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">修改时间：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="input-group date">-->
<!--                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                        <input name="updatedTime" th:value="${#dates.format(jiaqinAdvertPlatform.updatedTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var memberList = [[${@memberServiceImpl.selectAllMember()}]];
        var companyList = [[${@companyService.selectAllCompany()}]];
        var supplyList = [[${@supplyServiceImpl.selectAllSupply()}]];
        var goodsList = [[${@goodsGoodsServiceImpl.selectAllGoodsGoods()}]];
        var nowComId = [[${jiaqinAdvertPlatform.resId}]];
        var prefix = ctx + "jiaqin/advertplatform";
        $("#form-advertplatform-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-advertplatform-edit').serialize());
            }
        }

        $("input[name='createdTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='updatedTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#iCoverUpload'
                ,url: '/common/upload' //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#iCoverShow').html("");
                        $('#iCoverShow').append('<img src="'+ result +'" alt="'+ file.name +'" style="width: 112px; height: 63px;">')
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    console.log(res);
                    $("#imgUrl").val(res.realPath);
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });

        $(document).ready(function () {
            $('.summernote').summernote({
                height: 300,
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $editable) {
                        // console.log('onChange:', contents, $editable);
                        var aHTML = $('.summernote').summernote('code');
                        console.log(aHTML);
                        $("#content").val(aHTML);
                    }
                }
            });

            var otype = $("#otype").val();
            console.log("-------"+otype);
            if(otype == 1){
                //个人名片
                var str = "<option>请选择个人名片</option>";
                for(i=0;i<memberList.length;i++){
                    var comId = memberList[i]["id"];
                    var comnName = memberList[i]["username"];
                    if(comId == nowComId){
                        str += "<option selected value='"+comId+"'>"+comnName+"</option>";
                    }else{
                        str += "<option value='"+comId+"'>"+comnName+"</option>";
                    }
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();
            }
            if(otype == 2){
                //企业名片隐藏商品参数和富文本
                //加载企业选择框
                //企业名片
                var str = "<option>请选择企业名片</option>";
                for(i=0;i<companyList.length;i++){
                    //
                    // for(var j in companyList[i]){
                    //     console.log(typeof j)
                    //     console.log(j+":"+companyList[i]["id"])
                    // }
                    var comId = companyList[i]["id"];
                    var comnName = companyList[i]["companyName"];
                    // console.log(comId);
                    if(comId == nowComId){
                        str += "<option selected value='"+comId+"'>"+comnName+"</option>";
                    }else{
                        str += "<option value='"+comId+"'>"+comnName+"</option>";
                    }
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();

            }
            if(otype == 3){
                //供应
                var str = "<option>请选择供应</option>";
                for(i=0;i<supplyList.length;i++){
                    var comId = supplyList[i]["id"];
                    var comnName = supplyList[i]["title"];
                    // console.log(comId);
                    if(comId == nowComId){
                        str += "<option selected value='"+comId+"'>"+comnName+"</option>";
                    }else{
                        str += "<option value='"+comId+"'>"+comnName+"</option>";
                    }
                }
                //商品隐藏企业参数和富文本
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();

            }
            if(otype == 4){
                var str = "<option>请选择商品</option>";
                for(i=0;i<goodsList.length;i++){
                    //
                    // for(var j in companyList[i]){
                    //     console.log(typeof j)
                    //     console.log(j+":"+companyList[i]["id"])
                    // }
                    var comId = goodsList[i]["id"];
                    var comnName = goodsList[i]["name"];
                    // console.log(comId);
                    if(comId == nowComId){
                        str += "<option selected value='"+comId+"'>"+comnName+"</option>";
                    }else{
                        str += "<option value='"+comId+"'>"+comnName+"</option>";
                    }
                }
                //商品隐藏企业参数和富文本
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();

            }
            if(otype == 5){
                //文本隐藏商品参数和企业
                $("#jumpLinkDiv").hide();
                $("#titleDiv").show();
                $("#imgUrlDiv").show();
                $("#contentDiv").show();
            }
        });

        function showInput(at){
            console.log("-----------------"+at);
            if(at == 1){
                //个人名片
                var str = "<option>请选择个人名片</option>";
                for(i=0;i<memberList.length;i++){
                    var comId = memberList[i]["id"];
                    var comnName = memberList[i]["username"];
                    console.log(memberList);
                    str += "<option value='"+comId+"'>"+comnName+"</option>";
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();
            }
            if(at == 2){
                //企业名片
                var str = "<option>请选择企业名片</option>";
                for(i=0;i<companyList.length;i++){
                    var comId = companyList[i]["memberId"];
                    var comnName = companyList[i]["companyName"];
                    // console.log(memberList);
                    str += "<option value='"+comId+"'>"+comnName+"</option>";
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();
            }
            if(at == 3){
                //供应
                var str = "<option>请选择供应</option>";
                for(i=0;i<supplyList.length;i++){
                    var comId = supplyList[i]["id"];
                    var comnName = supplyList[i]["title"];
                    // console.log(comId);
                    str += "<option value='"+comId+"'>"+comnName+"</option>";
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();
            }
            if(at == 4){
                //商城商品
                var str = "<option>请选择商品</option>";
                for(i=0;i<goodsList.length;i++){
                    //
                    // for(var j in companyList[i]){
                    //     console.log(typeof j)
                    //     console.log(j+":"+companyList[i]["id"])
                    // }
                    var comId = goodsList[i]["id"];
                    var comnName = goodsList[i]["name"];
                    // console.log(comId);
                    str += "<option value='"+comId+"'>"+comnName+"</option>";
                }
                $("#jumpLink").html("");
                $("#jumpLink").append(str);
                $("#titleDiv").hide();
                $("#imgUrlDiv").hide();
                $("#pricelDiv").hide();
                $("#contentDiv").hide();
            }
            if(at == 5){
                //富文本
                $("#jumpLinkDiv").hide();
                $("#titleDiv").show();
                $("#imgUrlDiv").show();
                $("#contentDiv").show();
            }
        }
    </script>
</body>
</html>
